package com.zmn.oms.business.impl.conf.reply;

import com.zmn.oms.business.interfaces.conf.returnvisitcontent.ReplyAnswerBService;
import com.zmn.oms.model.entity.conf.reply.ReplyAnswer;
import com.zmn.oms.model.entity.conf.reply.ReplyAnswerQuery;
import com.zmn.oms.services.interfaces.conf.reply.ReplyAnswerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 类描述：回访
 *
 * @author liuying
 * @date 2022/03/09 19:27
 */
@Service
@Slf4j
public class ReplyAnswerBServiceImpl implements ReplyAnswerBService {
    @Resource
    private ReplyAnswerService replyAnswerService;

    @Override
    public List<ReplyAnswer> listByQuery(ReplyAnswerQuery replyAnswerQuery) {
        if (Objects.nonNull(replyAnswerQuery.getAnswerIdStr()) && CollectionUtils.isEmpty(replyAnswerQuery.getAnswerIdList()) && replyAnswerQuery.getAnswerIdStr().length() > 2) {
            // 去掉首尾的字符串
            String answerIdStr = replyAnswerQuery.getAnswerIdStr();
            answerIdStr = answerIdStr.substring(1, answerIdStr.length() - 1);
            String[] answerIdArr = answerIdStr.split("$");
            List<Integer> answerIdList = new ArrayList<>(answerIdArr.length);
            for (int i = 0; i < answerIdArr.length; i++) {
                answerIdList.add(Integer.parseInt(answerIdArr[i]));
            }
            replyAnswerQuery.setAnswerIdList(answerIdList);
        }

        List<ReplyAnswer> replyAnswerList = replyAnswerService.listByQuery(replyAnswerQuery);
        return replyAnswerList;

    }
}
